package com.shaoshaohuo.app.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shaoshaohuo.app.BigbitmapUtils;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.DetailsEntity;

import java.io.Serializable;

/**
 * Created by Administrator on 2017/6/9.
 */

public class DetailsFragmentBottom extends Fragment {
    public static DetailsFragmentBottom newInstance(Serializable s) {

        Bundle args = new Bundle();
        args.putSerializable("bottom", s);
        DetailsFragmentBottom fragment = new DetailsFragmentBottom();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_details_bottmlayhout, null);

        return inflate;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        LinearLayout fragment_detalis_bottom_lin = (LinearLayout) view.findViewById(R.id.fragment_detalis_bottom_lin);
        Bundle arguments = getArguments();
        DetailsEntity bottom = (DetailsEntity) arguments.getSerializable("bottom");
        String img_details = bottom.getData().getImg_details();
        if(img_details!=null&&img_details.length()>0){
            BigbitmapUtils.BigImage(img_details, getContext(), fragment_detalis_bottom_lin);
        }

        String scope = bottom.getData().getScope();
        String homeland = bottom.getData().getHomeland();
        TextView fragment_detalis_bottom_psfw = (TextView) view.findViewById(R.id.fragment_detalis_bottom_psfw);
        fragment_detalis_bottom_psfw.setText(scope);
        TextView fragment_detalis_bottom_cd = (TextView) view.findViewById(R.id.fragment_detalis_bottom_cd);
        fragment_detalis_bottom_cd.setText(homeland);
        TextView fragment_detalis_bottom_yyjz = (TextView) view.findViewById(R.id.fragment_detalis_bottom_yyjz);
        fragment_detalis_bottom_yyjz.setText(bottom.getData().getWork());
        GridLayout viewById = (GridLayout) view.findViewById(R.id.grd);

        for (int i = 0; i < viewById.getChildCount(); i++) {
            View childAt = viewById.getChildAt(i);
            GridLayout.LayoutParams layoutParams = (GridLayout.LayoutParams) childAt.getLayoutParams();
            layoutParams.width = getResources().getDisplayMetrics().widthPixels / 5;
            childAt.setLayoutParams(layoutParams);
        }

        TextView tv_pinm = (TextView) view.findViewById(R.id.tv_pinm);
        String name = bottom.getData().getName();
        tv_pinm.setText("品名：" + name);
        //表格
        TextView tv_waiguan = (TextView) view.findViewById(R.id.tv_waiguan);
        tv_waiguan.setText(bottom.getData().getOutlook());
        TextView tv_kougan = (TextView) view.findViewById(R.id.tv_kougan);
        tv_kougan.setText(bottom.getData().getTaste_details());
        TextView tv_baozhuang = (TextView) view.findViewById(R.id.tv_baozhuang);
        tv_baozhuang.setText(bottom.getData().getMbn_details());
        //特級
        TextView teji_danguo = (TextView) view.findViewById(R.id.teji_danguo);
        teji_danguo.setText(bottom.getData().getSuperStand());
        TextView teji_guige = (TextView) view.findViewById(R.id.teji_guige);
        teji_guige.setText(bottom.getData().getSuperDetail());
        //一级
        TextView yiji_danguo = (TextView) view.findViewById(R.id.yiji_danguo);
        yiji_danguo.setText(bottom.getData().getOneStand());
        TextView yi_guige = (TextView) view.findViewById(R.id.yi_guige);
        yi_guige.setText(bottom.getData().getOneDetail());
        //二級
        TextView erji_danguo = (TextView) view.findViewById(R.id.erji_danguo);
        erji_danguo.setText(bottom.getData().getTwoStand());
        TextView erji_guige = (TextView) view.findViewById(R.id.erji_guige);
        erji_guige.setText(bottom.getData().getTwoDetail());

        //三級
        TextView sanji_danguo = (TextView) view.findViewById(R.id.sanji_danguo);
        TextView sanji_guige = (TextView) view.findViewById(R.id.sanji_guige);
        sanji_danguo.setText(bottom.getData().getThreeStand());
        sanji_guige.setText(bottom.getData().getThreeDetail());
    }
}
